package org.sipsl.gisystems.gentest.rte.commands;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import org.sipsl.gisystems.gentest.rte.util.DataParams;
import org.sipsl.gisystems.gentest.rte.util.GenericUtil;
import org.sipsl.gisystems.gentest.rte.util.Params;
import org.sipsl.gisystems.rte.Testsuite.Test.Zone.Apn.Charge;

public class ExpectedSub extends RteCommand {

	private long balance;
	private int cosp;
	
	public ExpectedSub(long balance, int cosp, Params p) {
		super(p);
		this.balance = balance;
		this.cosp = cosp;
		// TODO Auto-generated constructor stub
	}		

	
	@Override
	public String getScript(){
				
		return "MOD:SUBID,"+p.getMSISDN()+":PRIMARYBALANCE,"+ balance +";";
	}

	@Override
	public void  dumpScript(String title, int i){
		try  
		{
			String prefix = GenericUtil.MakePrefix(i);
			
		    FileWriter fstream = new FileWriter(title+"/"+prefix+":expectsub-New.exp"); //true tells to append data.
		    BufferedWriter out = new BufferedWriter(fstream);
		    GenericUtil.LOG(title+"/"+prefix+":expectsub-New.exp");
		    String phrase = "balance";
		    if (cosp == 0){
			    GenericUtil.LOG("MOD:SUBID,"+p.getMSISDN()+":PRIMARYBALANCE,"+ balance +";");
			    out.write("MOD:SUBID,"+p.getMSISDN()+":PRIMARYBALANCE,"+ balance +";\n");
		    }else if (cosp == 1){
			    GenericUtil.LOG("MOD:SUBID,"+p.getMSISDN()+":TOTALPRIMARYOC,"+ balance +";");
			    out.write("MOD:SUBID,"+p.getMSISDN()+":TOTALPRIMARYOC,"+ balance +";\n");
			    phrase = "outstanding charges";
		    }
		    out.flush();
		    out.close();
		    
		    if (balance != 0){
			    testDescription = "Expected " + phrase +
			    		" is "+ balance;
		    }else {
		    	testDescription = "Call is free of charge";
		    }
		}
		catch (Exception e)
		{
		    System.err.println("Error: " + e.getMessage());
		}
		
	}


}


//private String s;
//
//public SetBundle(Params p, String s) {
//	super(p);
//	this.s = s ;
//	// TODO Auto-generated constructor stub
//}
//
//public String getScript(){
//	return "MOD:SUBID,"+p.getMSISDN()+":ELEMENT,MAS01:IMOM_CMD,SUB_DTPBUNDLE:SB_CHANNEL_ID,:SB_PROMO_COS,"+p.getGeneric(s)+":SB_START_DATE,:SB_END_DATE,:SB_COST,:SB_START_TIME,:SB_END_TIME,;";
//}
//public void dumpScript(String title, int i){
//	try  
//	{
//		String prefix = new String();
//		if (i < 9){
//			prefix = "000"+i;
//		}
//		if (i > 9 && i < 99){
//			prefix = "00"+i;
//		}
//		(new File(title)).mkdir();
//	    FileWriter fstream = new FileWriter(title+"/"+prefix+"|"+title+":insertBundle.hpp", true); //true tells to append data.
//	    BufferedWriter out = new BufferedWriter(fstream);
//	    out.write("MOD:SUBID,"+p.getMSISDN()+":ELEMENT,MAS01:IMOM_CMD,SUB_DTPBUNDLE:SB_CHANNEL_ID,:SB_PROMO_COS,"+p.getGeneric(s)+":SB_START_DATE,:SB_END_DATE,:SB_COST,:SB_START_TIME,:SB_END_TIME,;");
//	    out.close();
//	}
//	catch (Exception e)
//	{
//	    System.err.println("Error: " + e.getMessage());
//	}
//	
//}
//
//
//}
